package com.huluobo.appbase.utils

import android.content.Context
import android.net.ConnectivityManager
import android.net.NetworkInfo

/**
 * Created by lc on 2023/2/28.
 * 判断网络连接的工具
 */
object NetWorkUtil {
    fun isConnected(context: Context): Boolean {
        val info = getActiveNetWorkInfo(context)
        return info?.isConnected ?: false
    }

    private fun getActiveNetWorkInfo(context: Context): NetworkInfo? {
        val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
        return cm.activeNetworkInfo
    }
}